package com.kdl.webconfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kdl.webconfig.entity.News;
import com.kdl.webconfig.enums.NewsStateEnum;
import com.kdl.webconfig.mapper.NewsMapper;
import com.kdl.webconfig.service.INewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kdl.webconfig.vo.config.NewsQueryReq;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 新闻配置表 服务实现类
 * </p>
 *
 * @author wcj
 * @since 2022-09-05
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements INewsService {

    @Resource
    private NewsMapper newsMapper;

    @Override
    public Page<News> queryPage(NewsQueryReq newsQueryReq) {
        Page<News> newsPage = new Page<>(newsQueryReq.getPageNo(), newsQueryReq.getPageSize());
        QueryWrapper<News> newsQueryWrapper = new QueryWrapper<>();
        newsPage = newsMapper.selectPage(newsPage, newsQueryWrapper);
        return newsPage;
    }

    @Override
    public List<News> selectListByLanType(Integer lanType) {
        QueryWrapper<News> newsQueryWrapper = new QueryWrapper<>();
        newsQueryWrapper.lambda().eq(News::getState, NewsStateEnum.publish.getCode());
        return newsMapper.selectList(newsQueryWrapper);
    }
}
